<template>
  <!--  <Empty />-->
  <div class="student-page">
    <div class="total-wrap">学员统计 {{ scrollPageState.total }}人</div>
    <div class="filter-wrap">
      <div class="filter-left">
        <n-popselect
          v-model:value="params.gender"
          :options="genderOptions"
          trigger="click"
          @update:value="refreshData"
        >
          <div class="filter-item">
            <div class="label">{{
              params.gender ? getEnumDataLabel('gender', params.gender) : '全部'
            }}</div>
            <n-icon size="20">
              <ChevronDownOutline />
            </n-icon>
          </div>
        </n-popselect>
        <n-popselect
          v-model:value="params.learningStageId"
          :options="learningStageOptions"
          trigger="click"
          @update:value="refreshData"
          style="max-height: 300px; overflow: auto"
        >
          <div class="filter-item">
            <div class="label">{{
              params.learningStageId
                ? getEnumDataLabel('LEARNING_STAGE', params.learningStageId)
                : '学习阶段'
            }}</div>
            <n-icon size="20">
              <ChevronDownOutline />
            </n-icon>
          </div>
        </n-popselect>
      </div>
      <div class="filter-right">
        <n-input
          v-model:value="params.name"
          class="search-input"
          placeholder="请输入学生姓名"
          @keydown.enter="refreshData"
        >
          <template #prefix>
            <n-icon>
              <SearchSharp />
            </n-icon>
          </template>
        </n-input>
      </div>
    </div>
    <n-scrollbar style="height: calc(100% - 182px)" @scroll="scrollChange">
      <n-spin :show="scrollPageState.loading">
        <div class="student-wrap">
          <div class="student-item" v-for="(item, i) in scrollPageState.data" :key="i">
            <div class="student-info">
              <avatar :src="item.pic" size="72" />
              <div class="student-desc">
                <div class="student-name">{{ item.name }}</div>
                <div class="student-label"
                  >{{ getEnumDataLabel('gender', item.gender) }} | {{ item.age }}岁 |
                  {{ item.learningStageName }}</div
                >
              </div>
              <n-icon size="24">
                <ChevronForwardOutline />
              </n-icon>
            </div>
            <div class="hr"></div>
            <div class="score-wrap">
              <div class="score-item">
                <div class="num">
                  <ExpressionEmoji :icon="item.scoreIcon" class="score-img" />
                </div>
                <div class="label">综合表现</div>
              </div>
              <div class="score-item">
                <div class="num">{{ item.courseCount }}</div>
                <div class="label">参与课节数</div>
              </div>
              <div class="score-item">
                <div class="num">{{ item.wordCount }}</div>
                <div class="label">习得字数</div>
              </div>
              <div class="score-item">
                <div class="num">{{ item.totalIntegral }}</div>
                <div class="label">累计积分</div>
              </div>
            </div>
          </div>
        </div>
        <empty
          v-if="scrollPageState.data.length === 0 && !scrollPageState.loading"
          style="height: 740px"
        />
        <n-divider
          style="font-size: 24px"
          v-if="!scrollPageState.loading && scrollPageState.data.length > 0"
        >
          {{ scrollPageState.finished ? '没有更多了' : '下拉加载更多' }}
        </n-divider>
      </n-spin>
    </n-scrollbar>
  </div>
</template>

<script lang="ts" setup>
  import { ref, reactive } from 'vue';
  import { ChevronDownOutline, SearchSharp, ChevronForwardOutline } from '@vicons/ionicons5';
  import { getStudentRecordList, StudentRecordInfo } from '@/api/course/index';
  import { useScrollPage } from '@/hooks/useScrollPage';
  import { getEnumDataLabel, getEnumsArray } from '@/enums/dataEnum';
  import {useCourse} from "@/store/modules/course";
  import ExpressionEmoji from "@/views/components/ExpressionEmoji/index.vue";

  const genderOptions = reactive([
    {
      label: '全部',
      value: '',
    },
    ...getEnumsArray('gender'),
  ]);
  const learningStageOptions = reactive([
    {
      label: '全部',
      value: '',
    },
    ...getEnumsArray('LEARNING_STAGE'),
  ]);
  const params = reactive({
    gender: '',
    age: '',
    learningStageId: '',
    name: '',
  });
  const { scrollPageRef, scrollPageState, scrollChange, refreshData } =
    useScrollPage<StudentRecordInfo>({
      loadData: async (e) => {
        const result = await getStudentRecordList({
          ...e,
          ...params,
        });
        result.records.forEach(item => {
          const integralResult: any = useCourse().calcIntegralSettingData(item.score)
          item.scoreIcon = integralResult.icon
        })
        return result
      },
    });
</script>

<style lang="less" scoped>
  .student-page {
    height: 100%;
    display: flex;
    flex-direction: column;
    .total-wrap {
      font-size: 48px;
      line-height: 60px;
      margin-bottom: 32px;
    }
    .filter-wrap {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 30px;
      .filter-left {
        display: flex;
        align-items: center;
      }
      .filter-item {
        display: flex;
        align-items: center;
        font-size: 24px;
        margin-right: 36px;
        cursor: pointer;
        .label {
          margin-right: 6px;
        }
      }
      .filter-right {
        width: 700px;
        ::v-deep(.n-input) {
          border-radius: 9px;
          height: 60px;
          .n-input__border {
            border: 0;
          }
        }
      }
    }
    .student-wrap {
      display: flex;
      flex-wrap: wrap;
      //justify-content: space-between;
    }
    .student-item {
      width: 450px;
      height: 240px;
      background-color: #fff;
      border-radius: 12px;
      padding: 24px;
      cursor: pointer;
      margin-bottom: 18px;
      margin-right: 16px;
      &:nth-child(4n + 4) {
        margin-right: 0;
      }
      .student-info {
        display: flex;
        align-items: center;
        .avatar {
          width: 72px;
          height: 72px;
          border-radius: 50%;
        }
        .student-desc {
          flex: 1;
          margin: 0 16px;
        }
        .student-name {
          font-size: 24px;
        }
        .student-label {
          font-size: 21px;
          color: #9ba2aa;
        }
      }
      .hr {
        width: 100%;
        height: 2px;
        background: #e6eaed;
        margin: 24px 0;
      }
      .score-wrap {
        display: flex;
        .score-item {
          width: 25%;
          text-align: center;
          .score-img {
            display: block;
            margin: 0 auto;
            width: 36px;
            height: 36px;
          }
          .num {
            font-size: 30px;
            line-height: 36px;
            margin-bottom: 6px;
          }
          .label {
            font-size: 18px;
            color: #9ba2aa;
          }
        }
      }
    }
  }
</style>
